<div id="tmp">
	<div class="col-md-offset-4 col-md-5">
		<div class="box box-primary">
			<div class="box-header with-border">
				<h3 class="box-title">修改{{vue.tmpUser[1]}}的登录密码</h3>
			</div>
			<form role="form" onsubmit="return false;">
				<!-- /.box-header -->
				<div class="box-body">
					<div class="form-group" onsubmit="return false;">
						<label>登录密码</label>
						<input onkeyup="pw_1(this)" name="password" type="password" class="form-control" placeholder="登录密码 ...">
						<span style="color: red;" class="help-block" v-text="pw_1"></span>
					</div>

					<div class="form-group">
						<label>再次输入</label>
						<input onkeyup="pw_2(this)" value="" type="password" class="form-control" placeholder="再次输入 ...">
						<span style="color: red;" class="help-block" v-text="pw_2"></span>
					</div>
				</div>
				<!-- /.box-body -->
				<div class="box-footer text-center">
					<button type="reset" class="btn btn-info">重置</button>
					<button type="button" onclick="updatePassword()" class="btn btn-info">修改</button>
				</div>
			</form>
		</div>
		<!-- /.box -->
	</div>
</div>
<script>
	/*显示dialog的js
	 qiao.bs.dialog({
	 id : 'showUser',
	 url :'./showUser.htm',
	 head:false,
	 foot:false,
	 backdrop: true,
	 big : true
	 },function () {
	 return true;
	 });
	 */
    var tmp = new Vue({
        el: '#tmp',
        data: {img:'',pw_1:'',pw_2:''},
        methods:{
        }
    });

    var setImg = function (username) {
        if(!isEmpty(username)){
            $.ajax({
                url:'isHeadImg',
                type:'post',
                data:{username:username},
                success:function (result) {
                    if(result){
						tmp.img = '../images/head/'+username+'.jpg';
                    }else{
                        tmp.img = '../images/head/avatar.png';
					}
                }
            });
        }
    }

    var pw_1 = function (obj) {
        if (!verifyStrLength($(obj).val(), 5,12)) {
            tmp.pw_1 = '密码长度5-12';
        } else {
            tmp.pw_1 = '';
        }
    }

    var pw_2 = function (obj) {
        if ($(obj).val() != $('input[name=password]').val()) {
            tmp.pw_2 = '两次密码不相同';
        } else {
            tmp.pw_2 = '';
        }
    }

    var updatePassword = function () {
        if(tmp.pw_1.length == 0 && tmp.pw_2.length == 0){
            if(isEmpty($($("input[type=password]")[0]).val())
                || isEmpty($($("input[type=password]")[1]).val())){
                qiao.bs.alert('密码不能为空');
                return;
            }else
            $.ajax({
                type:'post',
                url:'updateUserPwd',
                data:{pwd:hex_md5($.trim($('input[name=password]').val()))
                    ,uid:vue.tmpUser[0]},
                success:function (result) {
                    if(result){
                        $("#editUser").modal('hide');
                        $('input[type=password]').val('');
                        qiao.bs.alert('密码更新成功');
                    }else{
                        qiao.bs.alert('参数不匹配……');
                    }
                }
            });
        }else{
            qiao.bs.alert('密码不符合要求……');
        }
    }

    $('input[type=password]').on('keyup',function (e) {
		if(e.keyCode == 13){
		    updatePassword();
		}
    });

    $(function () {
        var style = 'position: fixed; top: 0px; display: block; padding-left: 17px;';
        $("div[role=dialog]").attr("style", style);
        $("div.modal-content").removeClass('modal-content');
    });


</script>
